<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="button" value="响应数据是json字符串" onclick="method01()"> <br>
    <div id="messageDiv"></div>
    <table width="500px" cellspacing="0px" cellpadding="5px" border="1px" id="myform">
        <tr>
            <th>id</th>
            <th>name</th>
            <th>age</th>
        </tr>
        <!-- <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>   -->
        </form>


        <script type="text/javascript" src="../axios/axios-0.18.0.js"></script>
        <script type="text/javascript">


            let method01 = () => {
                axios.get("http://localhost:8080/axiosJsonDemo01Servlet")
                    .then((response) => {
                        let form = document.getElementById("myform")
                        let obj = response.data
                        if (obj.flag) {
                            let arr = obj.valueData
                            let content = ""
                            for (let friend of arr) {
                                content += `
                                <tr>
                                    <td>${friend.id}</td>
                                    <td>${friend.name}</td>
                                    <td>${friend.age}</td>
                                </tr>  
                                `
                            }
                            form.innerHTML += content
                        } else {
                            document.getElementById('messageDiv').innerHTML = obj.message
                        }
                    })
                    .catch()
                    .finally()
            }


        </script>
</body>

</html>